package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbSeckillGoodsMapper;
import com.bw1806.pojo.TbSeckillGoods;
import com.bw1806.pojo.TbSeckillGoodsExample;
import com.bw1806.sellergoods.service.TbSeckillGoodsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbSeckillGoodsServiceImpl implements TbSeckillGoodsService {

    @Autowired
    private TbSeckillGoodsMapper tbSeckillGoodsMapper;

    @Override
    public List<TbSeckillGoods> findAll() {
        return tbSeckillGoodsMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbSeckillGoods> pagelist(TbSeckillGoods tbSeckillGoods,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbSeckillGoodsExample example=new TbSeckillGoodsExample();

        TbSeckillGoodsExample.Criteria criteria = example.createCriteria();

        if(tbSeckillGoods!=null){
            //if(tbSeckillGoods.getName()!=null && tbSeckillGoods.getName().length()>0){
            //    criteria.andNameLike("%"+tbSeckillGoods.getName()+"%");
           // }
        }

        Page<TbSeckillGoods> page= (Page<TbSeckillGoods>) tbSeckillGoodsMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbSeckillGoods tbSeckillGoods) {
        Long id = tbSeckillGoods.getId();
        if(id != null && id !=0){
            tbSeckillGoodsMapper.updateByPrimaryKey(tbSeckillGoods);
        } else{
            tbSeckillGoodsMapper.insert(tbSeckillGoods);
        }
    }

    @Override
    public TbSeckillGoods getById(Long id) {
        return tbSeckillGoodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbSeckillGoodsMapper.deleteByPrimaryKey(id);
        }
        //tbSeckillGoodsMapper.deletebth(ids);
    }
}
